/**
Copyright (c) 2008 Arnaud Fabre <arnaud333@gmail.com>

This file is part of Vos Tutos Offline.

Vos Tutos Offline is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Vos Tutos Offline is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Vos Tutos Offline.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "latexconfig.h"
#include "alert.h"

#include <QSettings>

LatexConfigDialog::LatexConfigDialog(QWidget *parent) : QDialog(parent)
{
    setupUi(this);
    readConfig();

    connect(buttonBox, SIGNAL(accepted()), this, SLOT(save()));
}
	
void LatexConfigDialog::readConfig()
{
    QSettings settings("VTO", "Vos Tutos Offline");
    author->setText( settings.value("latexconfig/author").toString() );
    headerlatex->setPlainText( settings.value("latexconfig/header").toString() );
    showdate->setChecked( settings.value("latexconfig/showdate").toBool() );
    customHeader->setChecked( settings.value("latexconfig/customheader").toBool() );
}

void LatexConfigDialog::save()
{
    QSettings settings("VTO", "Vos Tutos Offline");
    settings.setValue("latexconfig/fontsize", fontsize->currentText());
    settings.setValue("latexconfig/encodingtype", encodingtype->currentText());
    settings.setValue("latexconfig/paperformat", paperformat->currentText());
    settings.setValue("latexconfig/showdate", showdate->isChecked());
    settings.setValue("latexconfig/author", author->text());

    settings.setValue("latexconfig/customheader", customHeader->isChecked());
    settings.setValue("latexconfig/header", headerlatex->toPlainText());

    QStringList opts;
    QList<QListWidgetItem *> sel = optionlist->selectedItems();
	
    for (int i = 0; i < sel.size(); ++i) {
	opts << sel.at(i)->text(); 
    }
	
    settings.setValue("latexconfig/optionlist", opts);
	
		
    VTOAlert::alert(500);
	
    accept();
}


